import Vue from 'vue'
import App from '@/App.vue';
import '@/libs/webim';
import 'amfe-flexible'
import '@/cube-ui';
import '@/styles/base.styl';
import '@/styles/material.styl';
// import '@/utils/typings';
import '@/components';
import '@/libs/json2';
import '@/libs/spark-md5';

import router from '@/routes'
import store from '@/store';
import VueSocket from 'vue-socket.io';
import { VueHammer } from 'vue2-hammer';
import { Role, GroupRole } from '@/utils/constants';
import VueQrcode from '@chenfengyuan/vue-qrcode';

import socket from '@/api/socket';
import VueRouter, { NavigationGuard } from 'vue-router';
import { server } from '@/api/socket/config';

// import VConsole from 'vconsole';
// new VConsole();

// import ClipboardJS from 'clipboard';
import { Api } from './api/http';

declare module 'vue/types/vue' {
  interface Vue {
    $socket: VueSocket,
    $createImagePreview: any;
    $createActionSheet: any;
    $createToast: any;
    $createDialog: any;
  }
}

declare module "vue/types/options" {
  interface ComponentOptions<V extends Vue> {
    router?: VueRouter;
    beforeRouteEnter?: NavigationGuard<V>;
    beforeRouteLeave?: NavigationGuard<V>;
    beforeRouteUpdate?: NavigationGuard<V>;
    sockets?: any;
  }
}
Vue.config.productionTip = false;

Vue.filter('Role', (val: any) => {
  if (val && val.toString()) {
    return Role[val.toString()];
  }
});

// 群聊中 服务端返回的type
Vue.filter('GroupRole', (val: any) => {
  if (val && val.toString()) {
    return GroupRole[val.toString()];
  }
});


// const $socket = new VueSocket({
//   debug: true,
//   connection: `${server.url}:${server.port}`,
// })

if (window.location.href.match('56900')) {
  Vue.use(VueSocket, `${server.url}:${server.port}`);
} else {
  Api.getReloadHref.r().then(({ data }: any) => {
    Vue.use(VueHammer);
    Vue.use(VueSocket, data.data.serverAddr);
    Vue.component(VueQrcode.name, VueQrcode);

    // document.addEventListener('DOMContentLoaded', () => {
    const $Vue = new Vue({
      router,
      store,
      render: h => h(App),
    });
    $Vue.$mount('#app');
    window['$Vue'] = $Vue;
    // window['ClipboardJS'] = ClipboardJS;
    // });
  });
}



// 启用文本socket连接
// Vue.use($socket);

